<template>
  <el-container>
    <!-- 头部 -->
    <el-header>
      <div class="logo">后台管理</div>
      <div class="header-right">
        <div>超级管理员</div>
        <div class="logout" @click="logout">退出</div>
      </div>
    </el-header>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="collapse ? '64px' : '200px'">
        <el-menu unique-opened :collapse="collapse" :collapse-transition="false" router
          :default-active="defaultActiveUrl" @select="selectMeun">
          <div class="collapse" @click="toggleCollapse">|||</div>
          <el-submenu :index="item.id + ''" v-for="item in asideList" :key="item.id">
            <template slot="title">
              <i :class="item.icon"></i>
              <span>{{ item.authName }}</span>
            </template>
            <el-menu-item :index="'/' + item2.path + ''" v-for="item2 in item.children" :key="item2.id">
              <i class="el-icon-menu"></i>
              <span>{{ item2.authName }}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主体 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
  export default {
    data() {
      return {
        // 左侧菜单列表
        asideList: [{
          authName: "用户管理",
          id: 1,
          children: [{
            authName: "用户管理",
            id: 2,
            path: 'user'
          }]
        }],
        // 左侧菜单折叠
        collapse: false,
        // 默认高亮的左侧菜单
        defaultActiveUrl: sessionStorage.getItem("menu")
      };
    },
    methods: {
      
      // 退出
      logout() {
        sessionStorage.clear();
        this.$router.push("/login");
      },
      // 折叠左侧菜单
      toggleCollapse() {
        this.collapse = !this.collapse;
      },
      // 选择每一个菜单
      selectMeun(index) {
        sessionStorage.setItem("menu", index);
      }
    }
  };

</script>

<style lang="less" scoped>
  .el-header {
    background: #4898f1;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .logo {
      font-weight: 700;
      font-size: 28px;
      color: #fff;
    }

    .header-right {
      display: flex;
      color: #fff;

      .logout {
        cursor: pointer;
        color: #fff;
        font-size: 16px;
        padding-right: 20px;
        margin-left: 20px;
      }
    }
  }

  .el-aside {
    background: #fff;
    height: calc(100vh - 60px);

    .collapse {
      background: #c1daf5;
      font-size: 10px;
      line-height: 24px;
      color: #fff;
      text-align: center;
      letter-spacing: 0.2em;
      cursor: pointer;
    }
  }

  .el-main {
    background: #f5f5f5;
  }

</style>
